"""Contains runtime classes for service and method definition."""

__author__ = 'gatis@google.com (Igor Gatis)'

from protoserv.protocol_pb2 import RequestProto
from protoserv.protocol_pb2 import ResponseProto

def HttpEndpoint(object):
  def __init__(self, url):
    pass


def TcpEndpoint(object):
  def __init__(self, url):
    pass


def RpcServer(object):
  def register(self, skeleton):
    pass

  def bind(self, endpoint):
    pass

  def serve(self):
    pass


class ServiceSkel(object):
  def __init__(self, fullname, methods):
    self.fullname = fullname
    self.methods = methods


class MethodSkel(object):
  def __init__(self, fullname):
    self.fullname = fullname

  def new_input(self):
    raise NotImplementedError

  def new_output(self):
    raise NotImplementedError

  def invoke(self, controller, request, response):
    raise NotImplementedError


class RemoteCall(object):
  def __init__(self, method, request_proto, response_proto):
    self.method = method
    self.request_proto = request_proto
    self.response_proto = response_proto


class MethodResolver(object):
  def __init__(self):
    self.name_to_method = {}

  def resolve_method(self, remote_call):
    remote_call.response.

    remote_call = RemoteCall(None, request, response)
    method = None
    if request.HasField('cached_method_id'):
      # TODO(gatis): implement method caching.
      response.status_code = ResponseProto.METHOD_CACHING_NOT_SUPPORTED
      return remote_call
    method_fullname = '%s.%s' % (request.service, request.method)
    remote_call.method = self.name_to_method.get(method_fullname, None)
    if not remote_call.method:
      response.status_code = ResponseProto.METHOD_NOT_FOUND
      return remote_call

      

      method = self.id_to_method.get(request.cached_method_id, None)
      if not method:
        response_proto.status_code = 


